<?php

namespace App\Http\Controllers\Campaign\Platform;

use App\Http\Controllers\BaseApiController;
use App\Model\ReActivityApply;
use App\Services\Campaign\Platform\ActiveService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Lcobucci\JWT\Claim\Validatable;


class ActiveController extends BaseApiController
{
    private $service;
    private $result=[];
    //构造方法
    public function __construct(ActiveService $service)
    {
        //继承基类的构造方法
        parent::__construct();
        //依赖注入service
        $this->service=$service;
    }

    /**
     * 活动详情   查找活动数据
     */
    public function Activeshow(){
        //调用seervice  拿出所有数据
        $data=$this->service->SelAll();
        //判断查询出来的数据是否为空
        if($data==array()){
           return $this->fail('100');
        }
        //查询成功
        else{
           return $this->success($data);
        }
    }


    /**
     * 活动详情
     */
    public function ActiveOne(Request $request){
        //接值  判断是否为空
        $rules=[
            'id'=>'required|integer'
        ];
        //验证规则
        $valibeable=Validator::make($request->all(),$rules);
        if($valibeable->errors()->all()){
            $re=$valibeable->errors()->all();
            return $this->fail('101',$re);

        }
        //查询数据
        $data=$this->service->SelOne($request);
        if($data===array()){
            return $this->fail('100');
        }
        else{
            return $this->success($data);
        }
    }



    /**
     *  添加活动报名人
     * 添加接口
     */
    public function AddApply(Request $request){
        //接值
        //验证   判断非空
        $ruses=[
            'id'=>'required|integer',
            'tel'=>'required|numeric',
            'uname'=>'required',
            'informat'=>'required',
        ];
       if($error=$this->validate($ruses,$request)){
           return $error;
       }
       $length=mb_strlen($request['tel']);
       //判断手机号  是不是11位
        if($length!==11){
            return $this->fail(108);
        }

        $arr=$this->service->AddAlt($request);

//        返回错误信息
        if($arr!=200){
            return $this->fail($arr);
        }
        //成功
      else{
            return $this->success();
       }
    }

}
